﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using BLL;
using DAL;
using EDM;

namespace Utility
{
    public class RepositoryFactory
    {
        public static T SearchTnfo<T>()
        {
            T repositoryObject = default(T);
            string dataGetWay = System.Configuration.ConfigurationManager.AppSettings["DAL"];           

            if (dataGetWay == "ADO.NET")
            {
                if (typeof(T) == typeof(IStatusRepository))
                {
                    IStatusRepository tempRepository = (IStatusRepository)new DAL.StatusRepository();
                    repositoryObject = (T)tempRepository;
                }

                if (typeof(T) == typeof(IAuthorityRepository))
                {
                    IAuthorityRepository tempRepository = (IAuthorityRepository)new DAL.AuthorityRepository();
                    repositoryObject = (T)tempRepository;
                }

                if (typeof(T) == typeof(IRoleRepository))
                {
                    IRoleRepository tempRepository = (IRoleRepository)new DAL.RoleRepository();
                    repositoryObject = (T)tempRepository;
                }


            }
             if (dataGetWay == "EF")
            {
                if (typeof(T) == typeof(IStatusRepository))
                {
                    IStatusRepository tempRepository = (IStatusRepository)new EDM.StatusRepository();
                    repositoryObject = (T)tempRepository;
                }

                if (typeof(T) == typeof(IAuthorityRepository))
                {
                    IAuthorityRepository tempRepository = (IAuthorityRepository)new EDM.AuthorityRepository();
                    repositoryObject = (T)tempRepository;
                }

                if (typeof(T) == typeof(IRoleRepository))
                {
                    IRoleRepository tempRepository = (IRoleRepository)new EDM.RoleRepository();
                    repositoryObject = (T)tempRepository;
                }

            }

            return repositoryObject;
        }
    }
}
